package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TCandidateContact;
import com.ruoyi.system.service.ITCandidateContactService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 考生联系信息Controller
 * 
 * @author ruoyi
 * @date 2024-12-13
 */
@Controller
@RequestMapping("/system/contact")
public class TCandidateContactController extends BaseController
{
    private String prefix = "system/contact";

    @Autowired
    private ITCandidateContactService tCandidateContactService;

    @RequiresPermissions("system:contact:view")
    @GetMapping()
    public String contact()
    {
        return prefix + "/contact";
    }

    /**
     * 查询考生联系信息列表
     */
    @RequiresPermissions("system:contact:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TCandidateContact tCandidateContact)
    {
        startPage();
        List<TCandidateContact> list = tCandidateContactService.selectTCandidateContactList(tCandidateContact);
        return getDataTable(list);
    }

    /**
     * 导出考生联系信息列表
     */
    @RequiresPermissions("system:contact:export")
    @Log(title = "考生联系信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TCandidateContact tCandidateContact)
    {
        List<TCandidateContact> list = tCandidateContactService.selectTCandidateContactList(tCandidateContact);
        ExcelUtil<TCandidateContact> util = new ExcelUtil<TCandidateContact>(TCandidateContact.class);
        return util.exportExcel(list, "基础数据2");
    }

    /**
     * 新增考生联系信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存考生联系信息
     */
    @RequiresPermissions("system:contact:add")
    @Log(title = "考生联系信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TCandidateContact tCandidateContact)
    {
        return toAjax(tCandidateContactService.insertTCandidateContact(tCandidateContact));
    }

    /**
     * 修改考生联系信息
     */
    @RequiresPermissions("system:contact:edit")
    @GetMapping("/edit/{contactId}")
    public String edit(@PathVariable("contactId") Long contactId, ModelMap mmap)
    {
        TCandidateContact tCandidateContact = tCandidateContactService.selectTCandidateContactByContactId(contactId);
        mmap.put("tCandidateContact", tCandidateContact);
        return prefix + "/edit";
    }

    /**
     * 修改保存考生联系信息
     */
    @RequiresPermissions("system:contact:edit")
    @Log(title = "考生联系信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TCandidateContact tCandidateContact)
    {
        return toAjax(tCandidateContactService.updateTCandidateContact(tCandidateContact));
    }

    /**
     * 删除考生联系信息
     */
    @RequiresPermissions("system:contact:remove")
    @Log(title = "考生联系信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tCandidateContactService.deleteTCandidateContactByContactIds(ids));
    }

    @Log(title = "考生联系信息", businessType = BusinessType.IMPORT)
    @RequiresPermissions("system:contact:import")
    @PostMapping("/importData")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<TCandidateContact> util = new ExcelUtil<TCandidateContact>(TCandidateContact.class);
        List<TCandidateContact> userList = util.importExcel(file.getInputStream());
        String message = tCandidateContactService.importData(userList, updateSupport, getLoginName());
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<TCandidateContact> util = new ExcelUtil<TCandidateContact>(TCandidateContact.class);
        return util.importTemplateExcel("基础数据2模版");
    }
}
